package classi;

import java.util.TreeSet;

public class Studente extends Account implements Comparable<Studente> {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5738901902215191241L;
	private TreeSet<EsameSostenuto> carriera = null;
	

	public Studente(String username, String password, String nome,
			String cognome, String cf) {
		super(username, password, nome, cognome, cf);
		this.carriera = new TreeSet<EsameSostenuto>();
		
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result
				+ ((carriera == null) ? 0 : carriera.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (!(obj instanceof Studente))
			return false;
		Studente other = (Studente) obj;
		if (carriera == null) {
			if (other.carriera != null)
				return false;
		} else if (!carriera.equals(other.carriera))
			return false;
		return true;
	}
	public void aggiungiEsameInCarriera(EsameSostenuto a){
		this.carriera.add(a);
		
	}
	
	public boolean modificaEsameInCarriera(EsameSostenuto a,EsameSostenuto nuovo){
//		Appello tmp ;
		for(EsameSostenuto tmp:carriera){
			if(tmp.equals(a)){
				carriera.remove(tmp);
				carriera.add(nuovo);
				return true;
			}//if
		}//for
		return false;
	}//metodo
	
	public boolean eliminaEsameInCarriera(EsameSostenuto a){
		for(EsameSostenuto tmp:carriera){
			if(tmp.equals(a)){
				carriera.remove(tmp);
				return true;
			}//if
		}//for
		return false ;
	}//metodo

	public TreeSet<EsameSostenuto> getCarriera() {
		return carriera;
	}

	public void setCarriera(TreeSet<EsameSostenuto> carriera) {
		this.carriera = carriera;
	}
	
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("["+ this.getCognome()+" , "+this.getNome()+"]");
		return sb.toString();
	}

	@Override
	public int compareTo(Studente o) {
		return super.getCf().compareTo(o.getCf());

	}


}
